package com.cskaoyan.Day23;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

class SendTask implements Runnable {

    private DatagramSocket datagramSocket;
    private String ip;
    private Integer port;

    public SendTask(DatagramSocket datagramSocket, String ip, Integer port) {
        this.datagramSocket = datagramSocket;
        this.ip = ip;
        this.port = port;
    }

    @Override
    public void run() {
        Scanner sc = new Scanner(System.in);
        while (true) try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            DatagramPacket sendDatagramPacket = UDPUtils.getSendPacket("1111", ip, port);
            datagramSocket.send(sendDatagramPacket);

        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
